﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Permissions;
using System.Data;

namespace RH.EBS.Core.Repository.DBUtility
{
    [Serializable]
    public class SqlParameters : ISerializable
    {
        string m_name = "";
        object m_value = null;
        Type m_type = null;

        public SqlParameters()
        {
        }

        public SqlParameters(string name, object value, Type type)
        {
            m_value = value;
            m_name = name;
            m_type = type;
        }


        public string Name
        {
            set
            {
                m_name = value;
            }
            get
            {
                return m_name;
            }
        }

        public object Value
        {
            set
            {
                m_value = value;
            }
            get
            {
                return m_value;
            }
        }

        public Type PType
        {
            set
            {
                m_type = value;
            }
            get
            {
                return m_type;
            }
        }

        protected SqlParameters(SerializationInfo info, StreamingContext context)
        {
            m_name = info.GetString("m_name");
            m_type = (Type)info.GetValue("m_type", typeof(Type));
            try
            {
                m_value = info.GetValue("m_value", m_type);
            }
            catch
            {
                m_value = Convert.DBNull;
            }
        }

        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("m_name", m_name);
            info.AddValue("m_type", m_type, m_type.GetType());
            info.AddValue("m_value", m_value);
        }
    }
}
